import { expertInfoUpdateApi, expertInfoDeleteApi } from '/@/api/expertDatabase/expert';
import { ElLoading, ElMessageBox } from 'element-plus';
import router from '/@/router';

export function useOperate(routerParams?: any, handleAfter?: any) {
	//移入黑名单
	const moveInBlackList = () => {
		ElMessageBox.prompt('移入黑名单理由', '提示', {
			confirmButtonText: '确定',
			inputPattern: /^(?!\s*$).+/,
			inputErrorMessage: '黑名单理由不能为空',
		}).then(({ value }) => {
			const loading = ElLoading.service({
				lock: true,
				text: '移入黑名单中...',
			});
			expertInfoUpdateApi({ expertInfoId: routerParams.expertInfoId, reasonBlacklist: value, blacklist: '1' })
				.then(() => {
					handleAfter();
				})
				.finally(() => {
					loading.close();
				});
		});
	};
	//移入出黑名单
	const moveOutBlackList = () => {
		ElMessageBox.confirm('是否确定移出黑名单?', '操作确认', {
			confirmButtonText: '确认',
			cancelButtonText: '取消',
			type: 'warning',
		}).then(() => {
			const loading = ElLoading.service({
				lock: true,
				text: '正在移出...',
			});
			expertInfoUpdateApi({ expertInfoId: routerParams.expertInfoId, blacklist: '0', reasonBlacklist: '' })
				.then(() => {
					handleAfter();
				})
				.finally(() => {
					loading.close();
				});
		});
	};
	//详情页面跳转
	const routerGo = () => {
		router.push({
			path: '/expertDatabase/expert/operate/index',
			query: routerParams,
		});
	};
	//删除
	const deleteData = () => {
		ElMessageBox.confirm('是否确定删除?', '操作确认', {
			confirmButtonText: '确认',
			cancelButtonText: '取消',
			type: 'warning',
		}).then(() => {
			const loading = ElLoading.service({
				lock: true,
				text: '删除中...',
			});
			expertInfoDeleteApi({ expertInfoId: routerParams.expertInfoId })
				.then(() => {
					handleAfter();
				})
				.finally(() => {
					loading.close();
				});
		});
	};
	//columuns
	const columns: any = [
		{ prop: 'expertName', label: '姓名', width: 300 },
		{ prop: 'educationName', label: ' 学历', width: 300 },
		{ prop: 'workPlace', label: '工作单位', width: 300 },
		{ prop: 'incumbentStatusName', label: '在职状态', width: 300 },
		{ prop: 'jobTitleName', label: '职称', width: 200 },
		{ prop: 'expertTypeName', label: '专家类别', width: 200 },
		{ prop: 'industryFieldsName', label: '擅长行业领域', width: 200 },
		{ prop: 'commitTime', label: '提交时间', width: 300 },
	];
	return {
		moveInBlackList,
		moveOutBlackList,
		routerGo,
		deleteData,
		columns,
	};
}
